// store.ts
import { InjectionKey } from 'vue'
import { createStore, useStore as baseUseStore, Store } from 'vuex'
import { globalState, global } from './modules/global'
import { i18nState, i18n } from './modules/i18n'
import { userState, user } from './modules/user'

// 定义RootState接口，将所有模块类型放入
export interface RootState {
  global: globalState
  i18n: i18nState
  user: userState
}

export const key: InjectionKey<Store<RootState>> = Symbol()
export const store = createStore<RootState>({
  modules: { global, i18n, user }
})

// 定义自己的 `useStore` 组合式函数
export const useStore = () => {
  return baseUseStore(key)
}
